<?php
namespace Api\Controller;
use Api\Controller\ApibaseControlle;

class IndexController extends ApibaseController{
	protected $article_model;
	protected function _initialize() {
		$this->article_model = M('Article');
    }	

    /**
    *	首页
    **/
    public function index(){
    	$page = I('post.page',1,'intval');
        //数据分页
        $count = $this->article_model->where(array('is_recycle'=>0))->count();
        $page_num = 5;
        $page_count = ceil($count / $page_num);
        $limit = 0;
        if ($page > 0) {
            $limit = ($page - 1) * $page_num;
        }else{
            $limit = 0;
        }

        $data = array();
        $article_data = $this->article_model->where(array('is_recycle'=>0))->order(array('add_time'=>'desc'))->limit($limit,$page_num)->select();

        foreach($article_data as $article_key => $article_val) {
        	$tmp = array();
        	$tmp['title'] = $article_val['title'];
        	$tmp['article_img'] = $this->host_url.$article_val['img'];
        	$tmp['hits'] = $article_val['hits'];
        	$tmp['praise'] = $article_val['praise'];
        	$data[] = $tmp;
        }

        $this->ajax_return('200','success',$data);
    }
}